<?php
#
# author: Cody Sorgenfrey
# (c)2013 South Hill Calvary Chapel
#
include_once("../mysql/database_info.php");
include_once("common.php");
include_once("../mysql/common.php");
connect_select_test("ministryPages");
if (!$_GET['name']){
	printf("Missing ministry name.");
	break;
}
$ministry = mysql_fetch_array(mysql_query("SELECT * FROM `ministryPages` WHERE `searchTag` LIKE '%".$_GET['name']."%' LIMIT 0,1"));
$moreHtml = '<style type="text/css">h4{font-size:12pt; margin-bottom:0px;} td{font-family: Gnuolane;font-size: 14px; vertical-align:top;line-height:19px;} li{margin-top:0px;margin-bottom:0px;}</style>';
startPage($ministry['ministry'], $ministry['metaKey'], $ministry['metaDesc'],$moreHtml , NULL);
if ($ministry['reference']){
	printf("<p><i>\n");
	printf("\t%s<br>%s\n", $ministry['verse'], $ministry['reference']);
	printf("</i></p>\n");
}
$body = explode("\n\n", $ministry['body']);
for ($x=0;$x<count($body);$x++){
	printf("<p>\n");
	printf("\t%s\n", $body[$x]);
	printf("</p>\n");
}
if ($ministry['leaderName']){
	$leader = array ($ministry['leaderName'], $ministry['leaderPhone'], $ministry['leaderEmail']);
	ministryContactBlock($leader, $ministry['blessing']);
}
printf("<table style='width:%s;'>\n", "100%");
printf("\t<tr>\n");
if ($ministry['rightBarExtra']){
	printf("\t\t<td>\n");
	printf("<p>%s</p>", $ministry['rightBarExtra']);
	printf("\t\t</td>\n");
}
if ($ministry['resourceArray']){
	$resource = explode("\n", $ministry['resourceArray']);
	for ($x=0;$x<count($resource);$x++){
		$resource[$x] = explode(",", $resource[$x]);
	}
	printf("\t\t<td>\n");
	mMinistry_resource_table($resource, $ministry['resourceTitle']);
	printf("\t\t</td>\n");
}
printf("\t</tr>\n");
printf("\t<tr>\n");
if ($ministry['eventTag']){
	$now = date("Y-m-d", time());
	$query="SELECT * FROM `events` WHERE ministry='".$ministry['eventTag']."' && `start`>='$now' ORDER BY start ASC";
	$result=mysql_query($query) or die (mysql_error());
	$num_rows=mysql_num_rows($result);
	if ($num_rows > 0){
		printf("\t\t<td>\n");
		mMinistry_event_table($result, $num_rows);
		printf("\t\t</td>\n");	
	}
}
printf("\t</tr>\n");
printf("</table>\n");
endPage();
?>